<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>

	<link rel="stylesheet" href="{{__PUBLIC__}}/Bootstrap/Css/bootstrap.min.css" />
	<link rel="stylesheet" href="{{__PUBLIC__}}/Admin/add.css" />
	<script type="text/javascript" src='{{__PUBLIC__}}/jquery-1.7.2.min.js'></script>
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">

	<form action="" method='post'>
		<fieldset>
			<legend>添加商品</legend>
			<table class='table table-bordered table-hover'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
						<script type="text/javascript">
							$(function(){
								$('select[name=category_cid]').change(function(){
//									获取被选中的那个的tid
									var type_tid = $(':selected',this).attr('tid');
//									通过异步发送tid
									$.ajax({
//										请求地址
										url:'{{U('ajaxGetAttr')}}',
//										发送的数据
										data:{tid:type_tid},
//										请求类型
										type:'post',
//										返回的数据类型
										dataType:'json',
//										成功返回
										success:function(phpData){
//											属性
											var attr = '';
//											规格
											var spec = '';
											$.each(phpData,function(k,v){
//												如果是属性
												if(v.taclass == 0){
													attr += '<tr class="info"><td align="right">'+v.taname+'</td>';
													attr += '<td><select name="attr['+v.taid+']" id="">';
													attr += '<option value="">请选择</option>';
													$.each(v.tavalue,function(kk,vv){
														attr += '<option value="'+vv+'">'+vv+'</option>';
													});
													attr += '</select></td><input type="hidden" name="type_tid" value="'+v.type_tid+'"/></tr>';
												} else{
//													否则就是规格
													spec += '<tr class="info"><td align="right">'+v.taname+'</td>';
													spec += '<td><select name="spec['+v.taid+'][value][]" id="">';
													spec += '<option value="">请选择</option>';
														$.each(v.tavalue,function(kk,vv){
															spec += '<option value="'+vv+'">'+vv+'</option>';
														})
													spec += '</select></td>';
													spec += '<td>附加价格：<input name="spec['+v.taid+'][price][]" value="0" type="text"></td>';
													spec += '<td><span class="add-spec btn btn-success"><i class="icon-plus icon-white"></i>添加规格</span></td></tr>';
												}
												$('#attr').html(attr);
												$('#spec').html(spec);
											});
										}
									})
								})
//								添加规格
								$('.add-spec').live('click',function(){
//									找到父级的tr标签
									var tr = $(this).parents('tr');
//									克隆(克隆匹配的DOM元素并且选中这些克隆的副本。
									var trObj = tr.clone();
									$('.add-spec',trObj).removeClass('btn-success add-spec').addClass('btn-danger del-spec').html('<i class="icon-minus icon-white"></i>删除规格');
//									在下面插入
									tr.after(trObj);
								})
//								删除
								$('.del-spec').live('click',function(){
									$(this).parents('tr').remove();
								})
							})
						</script>
							<select name="category_cid" required="required">
								<option value="">-请选择-</option>
									{{foreach from="$cateData" value="$cate_v"}}
									<option value="{{$cate_v['cid']}}" tid="{{$cate_v['type_tid']}}" {{if value="$cate_v['cid'] eq $GoodsData['category_cid']"}} selected="" {{endif}}>{{$cate_v['_name']}}</option>
									{{endforeach}}
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="brand_bid" required="required">
								<option value="">-请选择-</option>
								{{foreach from="$brandData" value="$brand_v"}}
									<option value="{{$brand_v['bid']}}" {{if value="$brand_v['bid'] eq $GoodsData['brand_bid']"}} selected="" {{endif}}>{{$brand_v['bname']}}</option>
								{{endforeach}}
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname' value="{{$GoodsData['gname']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>商品昵称</td>
						<td>
							<input type="text" name='nick_name' value="{{$GoodsData['nick_name']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>商品描述</td>
						<td>
							<input type="text" name='des' value="{{$GoodsData['des']}}" style="width: 700px;"/>
						</td>
					</tr>
					<tr class="info">
						<td>货号</td> 
						<td>
							<input type="text" name='artnum' value="{{$GoodsData['artnum']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='unit' value="{{$GoodsData['unit']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='market_price' value="{{$GoodsData['market_price']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='shop_price'  value="{{$GoodsData['shop_price']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>库存</td>
						<td>
							<input type="text" name='inventory'  value="{{$GoodsData['inventory']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='click' value="{{$GoodsData['click']}}"/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
				<!--************属性************-->
				{{foreach from="$gsAttrData" value="$gsAttr_v"}}
				<tr class="info">
					<td align="right">{{$gsAttr_v['taname']}}</td>
					<td>
						<select name="attr[{{$gsAttr_v['type_attr_taid']}}]" id="">
							<option value="">-请选择-</option>
							{{foreach from="$gsAttr_v['attr']" value="$v"}}
									<option value="{{$v}}" {{if value="$gsAttr_v['gavalue'] eq $v"}} selected="" {{endif}}>{{$v}}</option>
								{{endforeach}}
						</select>
					</td>
					<input type="hidden" name="type_tid" value="1">
				</tr>
				{{endforeach}}
				<!--*************属性结束************************-->
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
				<!--********************规格*************************-->
				{{foreach from="$ggAttrData" value="$gg_v"}}
				<tr class="info">
					<td align="right">{{$gg_v['taname']}}</td>
					<td>
						<select name="spec[{{$gg_v['type_attr_taid']}}][value][]" id="">
							<option value="">-请选择-</option>
							{{foreach from="$gg_v['spec']" value="$gg_vv"}}
							<option value="{{$gg_vv}}" {{if value="$gg_v['gavalue'] eq $gg_vv"}} selected="" {{endif}}>{{$gg_vv}}</option>
							{{endforeach}}
						</select>
					</td>
					<td>附加价格：<input name="spec[{{$gg_v['type_attr_taid']}}][price][]" value="{{$gg_v['add_price']}}" type="text">
					</td>
					<td>
						<span class="add-spec btn btn-success">
							<i class="icon-plus icon-white"></i>添加规格
						</span>
						<span class="btn btn-danger del-spec">
							<i class="icon-plus icon-white"></i>删除规格
						</span>
					</td>
				</tr>
				{{endforeach}}
				<!--********************规格结束*********************************-->
			</table>
			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="info">
					<td>上传图片:</td>
					<td>
	<script type="text/javascript" src="{{__PUBLIC__}}/Admin/uploadify/jquery.uploadify.min.js"></script>
	<link rel="stylesheet" type="text/css" href="{{__PUBLIC__}}/Admin/uploadify/uploadify.css"/>
	<!--列表图 插件开始-->
	<div lab="uploadFile">
    <input id="file" type="file" multiple="true" name="lists_pic">
    	<!--<a href="javascript:$('#file').uploadify('upload')" style="display: inline-block;" class="btn btn-info">确认上传</a>-->
    			<!--<a href="javascript:$('#file').uploadify('cancel')" class="btn btn-danger">取消上传</a>-->
    <!--<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>-->
    <script type="text/javascript">
        $(function() {
            $('#file').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '{{__PUBLIC__}}/Admin/uploadify/uploadify.swf',
                'uploader' : '{{U('upload')}}',
                'buttonText':'重新选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 10,//上传文件数
                'width':85,
                'height':25,
                'cancelImg':true,
                'filesReplaced':1,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
					//转为json
                    data=$.parseJSON(data);
                    //获得图片地址
//                  alert(data);
                    $('#img').attr("src",data);
                    $('#lists_pic').attr("value",data);
                }
            });
        });
    </script>
    <div id="uploadList" style="width: 100px;">
        <ul>
			<li>
				{{if value="$GoodsData['lists_pic']"}}
				<div id="oldImg">
					<img id="img" src="{{__ROOT__}}/{{$GoodsData['lists_pic']}}" alt="" /><input type="hidden" name="lists_pic" id="lists_pic" value=""/>
				</div>
				{{endif}}
			</li>
        </ul>
    </div>
</div>
<!--列表图  插件结束-->
					</td>
					<td id='pic-list'></td>
				</tr>
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<!--放大镜 插件开始-->
						<div lab="uploadFile">
    <input id="file1" type="file" multiple="true" name="img">
    	<!--<a href="javascript:$('#file').uploadify('upload')" style="display: inline-block;" class="btn btn-info">确认上传</a>-->
    			<!--<a href="javascript:$('#file').uploadify('cancel')" class="btn btn-danger">取消上传</a>-->
    <!--<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>-->
    <script type="text/javascript">
        $(function() {
            $('#file1').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '{{__PUBLIC__}}/Admin/uploadify/uploadify.swf',
                'uploader' : '{{U('upload_more')}}',
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 10,//上传文件数
                'width':65,
                'height':25,
                'cancelImg':true,
                'filesReplaced':1,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
					//转为json
                    data=$.parseJSON(data);
                    //获得图片地址
                    var imageUrl = data.url;
                    var li="<li path='"+data.path+"' url='"+data.url+"' id='new_img'><img src='"+imageUrl+"'/><a href='javascript:;' id='close_img_new'>X</a><input type='hidden' name='img[]' value='"+data.path+"'/></li>";
                    $("#uploadList1 ul").prepend(li);
                }
            });
//          点击关闭标签
			$('#close_img').live('click',function(){
				$(this).parents('#goods_li').remove();
			})
//			新上传  关闭
			$('#close_img_new').live('click',function(){
				$(this).parents('#new_img').remove();
			})
//          点击 百度编辑器显示
			$('.next_show').click(function(){
				$(this).next().toggle(600);
			});
        });
    </script>
    <div id="uploadList1" style="width: 100px;">
        <ul>
        	{{if value="$gDetailImg"}}
        	{{foreach from="$gDetailImg" value="$img_v"}}
        	<li path="{{$img_v}}" url="{{__ROOT__}}/{{$img_v}}" id="goods_li">
        		<img src="{{__ROOT__}}/{{$img_v}}">
        			<a href="javascript:;" id="close_img">X</a>
        		<input type="hidden" name="img[]" value="{{$img_v}}">
        	</li>
        	{{endforeach}}
			{{endif}}
        </ul>
    </div>
</div>
					</td>
					<td id='photo-list'></td>
				</tr>
			</table>
			
			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">商品详细</th>
				</tr>
				<tr class="hide info">
					<td>
						<script type="text/javascript" charset="utf-8" src="{{__PUBLIC__}}/ueditor1_4_3/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="{{__PUBLIC__}}/ueditor1_4_3/ueditor.all.min.js"> </script>
		<script type="text/javascript" charset="utf-8" src="{{__PUBLIC__}}/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
		<script id="editor" type="text/plain" style="width:100%;height:500px;" name="detail">{{$gDetailData[0]['detail']}}</script>
		<script>
    		var ue = UE.getEditor('editor');
		</script>
					</td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">售后服务</th>
				</tr>
				<tr class="hide info">
					<td>
						<script id="editor1" type="text/plain" style="width:100%;height:500px;" name="serve">{{$gDetailData[0]['serve']}}</script>
						<script>
				    		var ue = UE.getEditor('editor1');
						</script>
					</td>
				</tr>
			</table>
			<input type="hidden" name='user_admin_uid' value='{{$_SESSION['uid']}}'/>
			<input type="hidden" name="gid" value="{{Q('get.gid',0,'intval')}}"/>
			<input type="submit" value="确认添加" class="btn btn-primary btn-block btn-large" />
		</fieldset>
	</form>

	</div>
	</div>
	</div>
</body>
</html>